package controllers;

import models.User;
import play.mvc.Http.Context;
import play.mvc.Result;
import play.mvc.Security;

public class Secure extends Security.Authenticator {

    @Override
    public String getUsername(Context ctx) {
        return User.find.byId(Long.valueOf(ctx.session().get("user"))).getUsername();
    }

    @Override
    public Result onUnauthorized(Context ctx) {
        return redirect(routes.Index.index());
    }

}
